package com.huang825172.sbog.Tabs.SoundAndExplore.VideoPage.View;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.huang825172.sbog.R;
import com.huang825172.sbog.Tabs.SoundAndExplore.VideoPage.Store.ViewDatas.CommentListItem;

import java.util.List;

import de.hdodenhof.circleimageview.CircleImageView;

public class VideoPageCommentListRecyclerViewAdapter extends RecyclerView.Adapter<VideoPageCommentListRecyclerViewAdapter.VH> {
    private List<CommentListItem> mData;

    public VideoPageCommentListRecyclerViewAdapter(List<CommentListItem> data) {
        this.mData = data;
    }

    @NonNull
    @Override
    public VH onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.recyclerview_comment_video_page, viewGroup, false);
        return new VH(v);
    }

    @Override
    public void onBindViewHolder(@NonNull VH vh, int i) {
        CommentListItem item = mData.get(i);
        vh.usernameTextView.setText(item.getUsername());
        vh.commentTextView.setText(item.getComment());
        vh.dateTextView.setText(item.getDate());
        vh.likeNumTextView.setText(String.valueOf(item.getLikeNum()));
        if (item.getLike()) {
            vh.LikeImageView.setImageResource(R.mipmap.video_like);
        } else {
            vh.LikeImageView.setImageResource(R.mipmap.video_unlike);
        }
        vh.photoImageView.setImageResource(R.mipmap.main_logo);
    }

    @Override
    public int getItemCount() {
        return mData.size();
    }

    public static class VH extends RecyclerView.ViewHolder {

        private CircleImageView photoImageView;
        private TextView usernameTextView;
        private TextView commentTextView;
        private TextView dateTextView;
        private ImageView LikeImageView;
        private TextView likeNumTextView;

        public VH(View v) {
            super(v);
            photoImageView = v.findViewById(R.id.VideoPageCommentListItemPhotoImageView);
            usernameTextView = v.findViewById(R.id.VideoPageCommentListItemUsernameTextView);
            commentTextView = v.findViewById(R.id.VideoPageCommentListItemTextView);
            dateTextView = v.findViewById(R.id.VideoPageCommentListTimeTextView);
            LikeImageView = v.findViewById(R.id.VideoPageCommentListLikeImageView);
            likeNumTextView = v.findViewById(R.id.VideoPageCommentListLikeNumTextView);
        }
    }
}
